//
// Created by 11510 on 2024/7/17.
//

#ifndef INC_02_EVENT_PASS_MAINWINDOW_H
#define INC_02_EVENT_PASS_MAINWINDOW_H

#include <QMainWindow>
#include <QDebug>
#include <QEvent>
#include <QWidget>
#include <QLabel>

class MyFilter: public QObject{
Q_OBJECT
public:
    MyFilter(QWidget *parent = nullptr){}
    bool eventFilter(QObject *watched, QEvent *event) override{
        if(event->type() == QEvent::MouseButtonRelease){
            qDebug()  << "event filter " << watched->objectName() << "mouse release";
        }
        /**
         * 返回true不走event
         * 返回false走event
         */
//        return true;
        return false;
    }
};

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow {
Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = nullptr);

    ~MainWindow() override;

    bool event(QEvent *e) override{
        if(e->type() == QEvent::MouseButtonRelease){
            qDebug() << objectName() << " " << "event";
        }
        return QMainWindow::event(e);
    }
    void mouseReleaseEvent(QMouseEvent *ev) override{
        qDebug() << objectName() << " " << "event handler";
    }
    QLabel *out;

private:
    Ui::MainWindow *ui;
};


#endif //INC_02_EVENT_PASS_MAINWINDOW_H
